package com.ketai.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ketai.dao.EvaluationDao;
import com.ketai.dao.impl.EvaluationDaoImpl;
import com.ketai.pojo.Evaluation;
import com.ketai.service.EvaluationService;
import com.ketai.vo.EvaluationVo;

import javax.naming.NamingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 高伟华
 * @Description:
 * @Date:Create In 2022-08-11 13:32
 **/
public class EvaluationServiceImpl implements EvaluationService {
    EvaluationDao evaluationDao = new EvaluationDaoImpl();
    @Override
    public List<EvaluationVo> getEvaluation() {
        try {
          return  evaluationDao.getEvaluation();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int addEvaluation(Evaluation evaluation) {
        try {
            return    evaluationDao.addEvaluation(evaluation);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int deleteEvaluationById(String id) {
        try {
          return  evaluationDao.deleteEvaluationById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return 0;
    }


    @Override
    public EvaluationVo getEvaluationById(String id) {
        try {
            return evaluationDao.getEvaluationById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int checkEvaluation(String id, String open, String desc) {
        String sql  ="update Evaluation set id=?";
        List params = new ArrayList();
        if(!StrUtil.isBlank(open)&&open.equals("on")){
            params.add(1);
        }else{
            sql+=" , `desc`=? ";
            params.add(2);
            params.add(desc);
        }
        sql+=" ,Created=now() ";
        System.out.println(sql);
        try {
            return  evaluationDao.checkEvaluation(sql,params.toArray());
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (NamingException e) {
            e.printStackTrace();
        }
        return 0;

    }


}
